<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\common\widgets\MyFileUpload;

/* @var $this yii\web\View */
/* @var $model app\models\Project */
/* @var $form yii\widgets\ActiveForm */
?>
<script type="text/javascript" src="js/qiniuupload/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/qiniuupload/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="js/qiniuupload/plupload/i18n/zh_CN.js"></script>
<script type="text/javascript" src="js/qiniuupload/ui.js"></script>
<script type="text/javascript" src="js/qiniuupload/qiniu.js"></script>
<script type="text/javascript" src="js/qiniuupload/highlight/highlight.js"></script>
<script type="text/javascript" src="js/qiniuupload/main.js"></script>

<div class="project-form">
    <h4><?= Html::encode($model->isNewRecord ? '新建项目>>' : '更新项目>>') ?></h4>
    <div class="panel panel-default">
        <!--<div class="panel-heading text-center" style="background: #003eff;color:white">project</div>-->
        <div class="panel-body">
            <?php
            $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal form-group'],
                        'fieldConfig' => [
                            'template' => "{label}<div class=\"col-lg-8\">{input}</div>",
                            'labelOptions' => ['class' => 'col-lg-4', 'style' => 'margin-right:-30px'],
                        ]
            ]);
            ?>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4" style="text-align:left;">
                    <?= $form->field($model, 'projectname')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'projectno')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'userid')->textInput(['maxlength' => true]) ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'chargeman')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'unit')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'projectfrom')->textInput(['maxlength' => true]) ?>
                </div>                
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'zhxtype')->dropDownList(['纵向项目' => '纵向项目', '横向项目' => '横向项目'], ['prompt' => '--请选择--']) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'projectlevel')->dropDownList(['国家级' => '国家级', '省部级' => '省部级', '厅级' => '厅级', '校级' => '校级'], ['prompt' => '--请选择--']) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'projectplantype')->dropDownList(['项目计划类型一' => '项目计划类型一', '项目计划类型二' => '项目计划类型二'], ['prompt' => '--请选择--']) ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'discipline')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'status')->dropDownList(['申请' => '申请', '立项' => '立项', '在研' => '在研', '结题' => '结题'], ['prompt' => '--请选择--']) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'projectmember')->textInput(['maxlength' => true]) ?>
                </div>
                <!--                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                                    <label class=" col-lg-4" style="margin-left:-15px;">项目成员</label>
                                    <div class="col-lg-8" style="margin-left:-15px;">-->

                <?php
//                        $members = GkyUser::find()->all();
//                        $currentMembers = [];
//                        foreach ($model->members as $member) {
//                            $currentMembers[] = $member->user_id;
//                        }
//                        
//                        echo Select2::widget([
//                            'name' => 'projectmember',
//                            'value' => $currentMembers,
//                            'data' => ArrayHelper::map($members, 'id', 'username'),
//                            'options' => ['placeholder' => '请添加成员', 'multiple' => true],
//                            'pluginOptions' => [
//                                'tags' => true,
//                                'allowClear' => true,
//                            ],
//                        ]);
                ?>
                <!--                    </div>
                                </div>-->
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'isfinish')->dropDownList(['1' => '是', '0' => '否'], ['prompt' => '请选择']) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_dxjf')->textInput() ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_zzjf')->textInput() ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_jhnhx')->textInput() ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_jhwhx')->textInput() ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_sbgzf')->textInput() ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_zcjf')->textInput() ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_ppf')->textInput() ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_zcjfhj')->textInput() ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'jf_syjf')->textInput() ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'member')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'projectmoney')->textInput(['maxlength' => true]) ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                    <?= $form->field($model, 'mark')->textarea() ?>
                </div>
            </div>



            <?php if (!$model->isNewRecord) {
                ?>
                <div class="form-group">
                    <label class="col-lg-2 control-label"><h4>已有文档</h4></label>
                    <ul class="list-unstyled project-files col-lg-12">
                        <?php
                        foreach ($model->upfiles as $document) {
                            ?>
                        <li class="col-lg-2"  style="float:left">
                                <div class="media">
                                    <div class="media-left">
                                        <a href="<?= $document->path ?>">
                                            <?php
                                                $path = $document->path;
                                                $filetyep = strtolower(substr($path, strrpos($path, '.') + 1)) ;
                                                
                                                 if ($filetyep == "xls" || $filetyep == "xlsx") {
                                                     ?>
                                             <img class="media-object" src="img/excel.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }else if($filetyep == "doc" || $filetyep == "docx"){
                                                     
                                                     ?>
                                              <img class="media-object" src="img/word.jpg" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }else if($filetyep == "ppt" || $filetyep == "pptx"){
                                                     ?>
                                            <img class="media-object" src="img/ppt.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }else if($filetyep == "txt"){
                                                     ?>
                                               <img class="media-object" src="img/text.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                 }else if($filetyep == "png" || $filetyep == "jpg" || $filetyep == "jpeg" ||$filetyep == "bmp"||$filetyep == "gif"){ 
                                                     ?>
                                               <!--<img class="media-object" src="img/zhaopian.png" alt="..." style="width:50px;height:50px;">-->
                                               <img class="media-object" src="<?= $path ?>" alt="..." style="width:50px;height:50px;">
                                                     <?php
                                                 }
                                                 else{ ?>
                                            <img class="media-object" src="img/file.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }
                                                
                                            ?>
                                           
                                        </a>
                                    </div>
                                </div>
                            <a href="<?= $path ?>"><?= $document->filename ?></a>
                            </li>

                            <?php
                            }
                            ?>
                    </ul>
                 
                </div>

            <?php }
            ?>





            <?= MyFileUpload::widget() ?>


            <div class="col-lg-12 col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <?= Html::submitButton('保存', ['class' => 'btn btn-success col-lg-offset-5 col-md-offset-5']) ?>
                    <?= Html::a('返回', ['index'], ['class' => 'btn btn-primary']) ?>
                </div>
            </div>


            <?php ActiveForm::end(); ?>
        </div>
    </div>
</div>

<script type="text/javascript">
//删除图片
    $('div[name=close]').on('click', function () {
        var check = confirm("你确定要删除吗？");
        var divid = $(this).attr("id");
        var tableid = divid.replace("img", "table");
        var imgid = divid.replace("img", "");
        var fileid = $("#" + imgid).attr("name");
        if (check) {
            $.ajax({
                url: 'index.php?r=project/close',
                type: 'post',
                data: {'fileid': fileid},
                dataType: "json",
                success: function (response) {
                    if (response.res) {
                        $("#" + tableid).remove();
                    } else {
                        alert("删除失败！");
                    }
                }
            });
        }
    });
</script>
